home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch19 / Distance.frm (.txt) < prev    next >
Visual Basic Form  |  1999-07-11  |  10KB  |  355 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDistance 
  3.    Caption         =   "Distance"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6330
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   6330
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton cmdLineToLine 
  13.       Caption         =   "Line P1/V1 to Line P2/V2"
  14.       Height          =   495
  15.       Left            =   2880
  16.       TabIndex        =   24
  17.       Top             =   1800
  18.       Width           =   1215
  19.    End
  20.    Begin VB.CommandButton cmdP2ToPlane 
  21.       Caption         =   "P2 to Plane P1/V1"
  22.       Height          =   495
  23.       Left            =   2880
  24.       TabIndex        =   22
  25.       Top             =   1200
  26.       Width           =   1215
  27.    End
  28.    Begin VB.CommandButton cmdP2toLine 
  29.       Caption         =   "P2 to Line P1/V1"
  30.       Height          =   495
  31.       Left            =   2880
  32.       TabIndex        =   20
  33.       Top             =   600
  34.       Width           =   1215
  35.    End
  36.    Begin VB.CommandButton cmdP1toP2 
  37.       Caption         =   "P1 to P2"
  38.       Height          =   375
  39.       Left            =   2880
  40.       TabIndex        =   18
  41.       Top             =   120
  42.       Width           =   1215
  43.    End
  44.    Begin VB.Frame Frame2 
  45.       Caption         =   "Vectors"
  46.       Height          =   975
  47.       Left            =   0
  48.       TabIndex        =   9
  49.       Top             =   1080
  50.       Width           =   2775
  51.       Begin VB.TextBox txtV2z 
  52.          Height          =   285
  53.          Left            =   2040
  54.          TabIndex        =   17
  55.          Text            =   "1"
  56.          Top             =   600
  57.          Width           =   615
  58.       End
  59.       Begin VB.TextBox txtV2y 
  60.          Height          =   285
  61.          Left            =   1320
  62.          TabIndex        =   16
  63.          Text            =   "1"
  64.          Top             =   600
  65.          Width           =   615
  66.       End
  67.       Begin VB.TextBox txtV2x 
  68.          Height          =   285
  69.          Left            =   600
  70.          TabIndex        =   15
  71.          Text            =   "1"
  72.          Top             =   600
  73.          Width           =   615
  74.       End
  75.       Begin VB.TextBox txtV1z 
  76.          Height          =   285
  77.          Left            =   2040
  78.          TabIndex        =   13
  79.          Text            =   "0"
  80.          Top             =   240
  81.          Width           =   615
  82.       End
  83.       Begin VB.TextBox txtV1y 
  84.          Height          =   285
  85.          Left            =   1320
  86.          TabIndex        =   12
  87.          Text            =   "1"
  88.          Top             =   240
  89.          Width           =   615
  90.       End
  91.       Begin VB.TextBox txtV1x 
  92.          Height          =   285
  93.          Left            =   600
  94.          TabIndex        =   11
  95.          Text            =   "0"
  96.          Top             =   240
  97.          Width           =   615
  98.       End
  99.       Begin VB.Label Label1 
  100.          Caption         =   "V2"
  101.          Height          =   255
  102.          Index           =   3
  103.          Left            =   240
  104.          TabIndex        =   14
  105.          Top             =   600
  106.          Width           =   255
  107.       End
  108.       Begin VB.Label Label1 
  109.          Caption         =   "V1"
  110.          Height          =   255
  111.          Index           =   2
  112.          Left            =   240
  113.          TabIndex        =   10
  114.          Top             =   240
  115.          Width           =   255
  116.       End
  117.    End
  118.    Begin VB.Frame Frame1 
  119.       Caption         =   "Points"
  120.       Height          =   975
  121.       Left            =   0
  122.       TabIndex        =   0
  123.       Top             =   0
  124.       Width           =   2775
  125.       Begin VB.TextBox txtP2z 
  126.          Height          =   285
  127.          Left            =   2040
  128.          TabIndex        =   8
  129.          Text            =   "1"
  130.          Top             =   600
  131.          Width           =   615
  132.       End
  133.       Begin VB.TextBox txtP2y 
  134.          Height          =   285
  135.          Left            =   1320
  136.          TabIndex        =   7
  137.          Text            =   "1"
  138.          Top             =   600
  139.          Width           =   615
  140.       End
  141.       Begin VB.TextBox txtP2x 
  142.          Height          =   285
  143.          Left            =   600
  144.          TabIndex        =   6
  145.          Text            =   "1"
  146.          Top             =   600
  147.          Width           =   615
  148.       End
  149.       Begin VB.TextBox txtP1z 
  150.          Height          =   285
  151.          Left            =   2040
  152.          TabIndex        =   4
  153.          Text            =   "0"
  154.          Top             =   240
  155.          Width           =   615
  156.       End
  157.       Begin VB.TextBox txtP1y 
  158.          Height          =   285
  159.          Left            =   1320
  160.          TabIndex        =   3
  161.          Text            =   "0"
  162.          Top             =   240
  163.          Width           =   615
  164.       End
  165.       Begin VB.TextBox txtP1x 
  166.          Height          =   285
  167.          Left            =   600
  168.          TabIndex        =   2
  169.          Text            =   "0"
  170.          Top             =   240
  171.          Width           =   615
  172.       End
  173.       Begin VB.Label Label1 
  174.          Caption         =   "P2"
  175.          Height          =   255
  176.          Index           =   1
  177.          Left            =   240
  178.          TabIndex        =   5
  179.          Top             =   600
  180.          Width           =   255
  181.       End
  182.       Begin VB.Label Label1 
  183.          Caption         =   "P1"
  184.          Height          =   255
  185.          Index           =   0
  186.          Left            =   240
  187.          TabIndex        =   1
  188.          Top             =   240
  189.          Width           =   255
  190.       End
  191.    End
  192.    Begin VB.Label lblLineToLine 
  193.       BorderStyle     =   1  'Fixed Single
  194.       Height          =   255
  195.       Left            =   4200
  196.       TabIndex        =   25
  197.       Top             =   1920
  198.       Width           =   1215
  199.    End
  200.    Begin VB.Label lblP2ToPlane 
  201.       BorderStyle     =   1  'Fixed Single
  202.       Height          =   255
  203.       Left            =   4200
  204.       TabIndex        =   23
  205.       Top             =   1320
  206.       Width           =   1215
  207.    End
  208.    Begin VB.Label lblP2ToLine 
  209.       BorderStyle     =   1  'Fixed Single
  210.       Height          =   255
  211.       Left            =   4200
  212.       TabIndex        =   21
  213.       Top             =   720
  214.       Width           =   1215
  215.    End
  216.    Begin VB.Label lblP1toP2 
  217.       BorderStyle     =   1  'Fixed Single
  218.       Height          =   255
  219.       Left            =   4200
  220.       TabIndex        =   19
  221.       Top             =   150
  222.       Width           =   1215
  223.    End
  224. Attribute VB_Name = "frmDistance"
  225. Attribute VB_GlobalNameSpace = False
  226. Attribute VB_Creatable = False
  227. Attribute VB_PredeclaredId = True
  228. Attribute VB_Exposed = False
  229. Option Explicit
  230. ' Shoe the distance between two lines.
  231. Private Sub cmdLineToLine_Click()
  232. Dim px1 As Single
  233. Dim py1 As Single
  234. Dim pz1 As Single
  235. Dim px2 As Single
  236. Dim py2 As Single
  237. Dim pz2 As Single
  238. Dim vx1 As Single
  239. Dim vy1 As Single
  240. Dim vz1 As Single
  241. Dim vx2 As Single
  242. Dim vy2 As Single
  243. Dim vz2 As Single
  244.     On Error GoTo LineToLineError
  245.     px1 = CSng(txtP1x.Text)
  246.     py1 = CSng(txtP1y.Text)
  247.     pz1 = CSng(txtP1z.Text)
  248.     px2 = CSng(txtP2x.Text)
  249.     py2 = CSng(txtP2y.Text)
  250.     pz2 = CSng(txtP2z.Text)
  251.     vx1 = CSng(txtV1x.Text)
  252.     vy1 = CSng(txtV1y.Text)
  253.     vz1 = CSng(txtV1z.Text)
  254.     vx2 = CSng(txtV2x.Text)
  255.     vy2 = CSng(txtV2y.Text)
  256.     vz2 = CSng(txtV2z.Text)
  257.     lblLineToLine.Caption = Format$( _
  258.         DistanceLineToLine( _
  259.             px1, py1, pz1, _
  260.             px2, py2, pz2, _
  261.             vx1, vy1, vz1, _
  262.             vx2, vy2, vz2), _
  263.             "0.0000")
  264.     Exit Sub
  265. LineToLineError:
  266.     MsgBox Err.Description
  267. End Sub
  268. ' Show the distance between point P2 and the
  269. ' line through P1 in direction V1.
  270. Private Sub cmdP2toLine_Click()
  271. Dim px1 As Single
  272. Dim py1 As Single
  273. Dim pz1 As Single
  274. Dim px2 As Single
  275. Dim py2 As Single
  276. Dim pz2 As Single
  277. Dim vx1 As Single
  278. Dim vy1 As Single
  279. Dim vz1 As Single
  280.     On Error GoTo P2ToLineError
  281.     px1 = CSng(txtP1x.Text)
  282.     py1 = CSng(txtP1y.Text)
  283.     pz1 = CSng(txtP1z.Text)
  284.     px2 = CSng(txtP2x.Text)
  285.     py2 = CSng(txtP2y.Text)
  286.     pz2 = CSng(txtP2z.Text)
  287.     vx1 = CSng(txtV1x.Text)
  288.     vy1 = CSng(txtV1y.Text)
  289.     vz1 = CSng(txtV1z.Text)
  290.     lblP2ToLine.Caption = Format$( _
  291.         DistancePointToLine( _
  292.             px2, py2, pz2, _
  293.             px1, py1, pz1, _
  294.             vx1, vy1, vz1), _
  295.             "0.0000")
  296.     Exit Sub
  297. P2ToLineError:
  298.     MsgBox Err.Description
  299. End Sub
  300. ' Show the distance between P1 and P2.
  301. Private Sub cmdP1toP2_Click()
  302. Dim px1 As Single
  303. Dim py1 As Single
  304. Dim pz1 As Single
  305. Dim px2 As Single
  306. Dim py2 As Single
  307. Dim pz2 As Single
  308.     On Error GoTo P1toP2Error
  309.     px1 = CSng(txtP1x.Text)
  310.     py1 = CSng(txtP1y.Text)
  311.     pz1 = CSng(txtP1z.Text)
  312.     px2 = CSng(txtP2x.Text)
  313.     py2 = CSng(txtP2y.Text)
  314.     pz2 = CSng(txtP2z.Text)
  315.     lblP1toP2.Caption = Format$( _
  316.         DistancePointToPoint( _
  317.             px1, py1, pz1, _
  318.             px2, py2, pz2), _
  319.             "0.0000")
  320.     Exit Sub
  321. P1toP2Error:
  322.     MsgBox Err.Description
  323. End Sub
  324. ' Show the distance between a point and a plane.
  325. Private Sub cmdP2ToPlane_Click()
  326. Dim px1 As Single
  327. Dim py1 As Single
  328. Dim pz1 As Single
  329. Dim px2 As Single
  330. Dim py2 As Single
  331. Dim pz2 As Single
  332. Dim vx1 As Single
  333. Dim vy1 As Single
  334. Dim vz1 As Single
  335.     On Error GoTo P2ToPlaneError
  336.     px1 = CSng(txtP1x.Text)
  337.     py1 = CSng(txtP1y.Text)
  338.     pz1 = CSng(txtP1z.Text)
  339.     px2 = CSng(txtP2x.Text)
  340.     py2 = CSng(txtP2y.Text)
  341.     pz2 = CSng(txtP2z.Text)
  342.     vx1 = CSng(txtV1x.Text)
  343.     vy1 = CSng(txtV1y.Text)
  344.     vz1 = CSng(txtV1z.Text)
  345.     lblP2ToPlane.Caption = Format$( _
  346.         DistancePointToPlane( _
  347.             px2, py2, pz2, _
  348.             px1, py1, pz1, _
  349.             vx1, vy1, vz1), _
  350.             "0.0000")
  351.     Exit Sub
  352. P2ToPlaneError:
  353.     MsgBox Err.Description
  354. End Sub
  355.